home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / nx_arc / arccvt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-20  |  3.7 KB  |  146 lines

  1. /*
  2.  * $Log:    arccvt.c,v $
  3.  * Revision 1.2  88/04/11  17:51:28  hyc
  4.  * re-synch wuth MTS, minor formatting
  5.  * 
  6.  * Revision 1.1  88/04/11  17:50:00  hyc
  7.  * Initial revision
  8.  * 
  9.  * Revision 1.1  87/12/19  04:02:03  hyc
  10.  * Initial revision
  11.  * 
  12.  * Revision 1.3  87/08/13  17:03:07  hyc
  13.  * Run thru the indent program...
  14.  *  Revision 1.2  87/07/21  06:57:53  hyc *** empty
  15.  * log message ***
  16.  * 
  17.  */
  18.  
  19. /*
  20.  * ARC - Archive utility - ARCCVT
  21.  * 
  22.  * Version 1.16, created on 02/03/86 at 22:53:02
  23.  * 
  24.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  25.  * 
  26.  * By:  Thom Henderson
  27.  * 
  28.  * Description: This file contains the routines used to convert archives to use
  29.  * newer file storage methods.
  30.  * 
  31.  * Language: Computer Innovations Optimizing C86
  32.  */
  33. #include <stdio.h>
  34. #include "arc.h"
  35.  
  36. static char     tempname[100];    /* temp file name */
  37.  
  38. INT
  39. cvtarc(num, arg)        /* convert archive */
  40.     INT             num;    /* number of arguments */
  41.     char           *arg[];    /* pointers to arguments */
  42. {
  43.     struct heads    hdr;    /* file header */
  44.     INT             cvt;    /* true to convert current file */
  45.     INT             did[25];/* true when argument was used */
  46.     INT             n;    /* index */
  47.     char           *makefnam();    /* filename fixer */
  48.     FILE           *fopen();/* file opener */
  49.     INT             cvtfile();
  50.  
  51.     if (arctemp)        /* use temp area if specified */
  52.         sprintf(tempname, "%s.CVT", arctemp);
  53.     else
  54.         makefnam("$ARCTEMP.CVT", arcname, tempname);
  55. #ifdef MTS
  56.     image = 1;
  57. #endif
  58.  
  59.     openarc(1);        /* open archive for changes */
  60.  
  61.     for (n = 0; n < num; n++)    /* for each argument */
  62.         did[n] = 0;    /* reset usage flag */
  63.     rempath(num, arg);    /* strip off paths */
  64.  
  65.     if (num) {        /* if files were named */
  66.         while (readhdr(&hdr, arc)) {    /* while more files to check */
  67.             cvt = 0;/* reset convert flag */
  68.             for (n = 0; n < num; n++) {    /* for each template
  69.                              * given */
  70.                 if (match(hdr.name, arg[n])) {
  71.                     cvt = 1;    /* turn on convert flag */
  72.                     did[n] = 1;    /* turn on usage flag */
  73.                     break;    /* stop looking */
  74.                 }
  75.             }
  76.  
  77.             if (cvt)/* if converting this one */
  78.                 cvtfile(&hdr);    /* then do it */
  79.             else {    /* else just copy it */
  80.                 writehdr(&hdr, new);
  81.                 filecopy(arc, new, hdr.size);
  82.             }
  83.         }
  84.     } else
  85.         while (readhdr(&hdr, arc))    /* else convert all files */
  86.             cvtfile(&hdr);
  87.  
  88.     hdrver = 0;        /* archive EOF type */
  89.     writehdr(&hdr, new);    /* write out our end marker */
  90.     closearc(1);        /* close archive after changes */
  91.  
  92.     if (note) {
  93.         for (n = 0; n < num; n++) {    /* report unused args */
  94.             if (!did[n]) {
  95.                 printf("File not found: %s\n", arg[n]);
  96.                 nerrs++;
  97.             }
  98.         }
  99.     }
  100. }
  101.  
  102. INT
  103. cvtfile(hdr)            /* convert a file */
  104.     struct heads   *hdr;    /* pointer to header data */
  105. {
  106.     LONG            starts, ftell();    /* where the file goes */
  107.     FILE           *tmp, *fopen();    /* temporary file */
  108. #ifdef MTS
  109.     char            name[16];
  110. #endif
  111.  
  112. #ifdef MTS
  113.     if (!(tmp = fopen(tempname, "w+b")))
  114. #else
  115.     if (!(tmp = fopen(tempname, "w+")))
  116. #endif
  117.         arc_abort("Unable to create temporary file %s", tempname);
  118.  
  119.     if (note) {
  120.         printf("Converting file: %-12s   reading, ", hdr->name);
  121.         fflush(stdout);
  122.     }
  123. #ifdef MTS
  124.     strcpy(name, hdr->name);
  125.     fseek(tmp, 0, 0);
  126. #endif
  127.     unpack(arc, tmp, hdr);    /* unpack the entry */
  128.     fseek(tmp, 0L, 0);    /* reset temp for reading */
  129.  
  130.     starts = ftell(new);    /* note where header goes */
  131.     hdrver = 8;        /* anything but end marker */
  132.     writehdr(hdr, new);    /* write out header skeleton */
  133.     pack(tmp, new, hdr);    /* pack file into archive */
  134.     fseek(new, starts, 0);    /* move back to header skeleton */
  135. #ifdef MTS
  136.     strcpy(hdr->name, name);
  137. #endif
  138.     writehdr(hdr, new);    /* write out real header */
  139.     fseek(new, hdr->size, 1);    /* skip over data to next header */
  140.     fclose(tmp);        /* all done with the file */
  141.     if (unlink(tempname) && warn) {
  142.         printf("Cannot unsave %s\n", tempname);
  143.         nerrs++;
  144.     }
  145. }
  146.